#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
class Testee{
public:
    string id;
    int score;
    int final_rank;
    int which_location;
    int local_rank;
    Testee(string id, int score, int which_location){
        this->id=id;
        this->score=score;
        this->which_location=which_location;
        this->final_rank=-1;
        this->local_rank=-1;
    }
    bool operator < (const Testee &t) const{
        if(this->score==t.score)
            return this->id<t.id;
        else
            return this->score>t.score;
    }
};
int main(){
    int nLocations;
    cin>>nLocations;
    vector<Testee> testees;
    vector<int> testees_num;
    int i=0;
    while(i<nLocations){
        int nTestees;
        cin>>nTestees;
        testees_num.push_back(nTestees);
        int j=0;
        while(j<nTestees){
            string id;
            int score;
            cin>>id>>score;

            Testee testee(id,score,i);
            testees.push_back(testee);

            j++;
        }
        i++;
    }

    int start=0;
    for(int i=0;i<testees_num.size();i++){
        int mend=start+testees_num[i];
        sort(testees.begin()+start,testees.begin()+mend);
        vector<Testee>::iterator it=testees.begin()+start;
        int trank=0;
        int lastscore=-1;
        int lastrank=-1;
        for(;it!=testees.begin()+mend;++it){
            trank++;
            if(lastscore!=(*it).score){
                (*it).local_rank=trank;
            }else
                (*it).local_rank=lastrank;
            lastscore=(*it).score;
            lastrank=(*it).local_rank;
        }
        start=mend;
    }
    sort(testees.begin(),testees.end());
    vector<Testee>::iterator it=testees.begin();
    int trank=0;
    int lastscore=-1;
    int lastrank=-1;
    for(;it!=testees.end();++it){
        trank++;
        if(lastscore!=(*it).score){
            (*it).final_rank=trank;
        }else
            (*it).final_rank=lastrank;
        lastscore=(*it).score;
        lastrank=(*it).final_rank;
    }
    cout<<testees.size()<<endl;
    for(int i=0;i<testees.size();i++){
        cout<<testees[i].id<<" "<<testees[i].final_rank
        <<" "<<testees[i].which_location+1
        <<" "<<testees[i].local_rank<<endl;
    }
    return 0;
}
